﻿using System;
using System.Collections.Generic;
using System.Text;
using box_test;
using System.Windows.Forms;
using Microsoft.DirectX;

namespace Lab1
{
    class MainWindow : System.Windows.Forms.Form
    {
        private System.Windows.Forms.Button button1;
        private Label label1;
        private TextBox radius;
        private Label label2;
        private TextBox height;
        private Label label3;
        private TextBox edge;
        private TextBox x1;
        private TextBox y1;
        private TextBox z1;
        private TextBox x4;
        private TextBox y4;
        private TextBox z4;
        private TextBox z2;
        private TextBox y2;
        private TextBox x2;
        private TextBox z5;
        private TextBox y5;
        private TextBox x5;
        private TextBox z6;
        private TextBox y6;
        private TextBox x6;
        private TextBox z3;
        private TextBox y3;
        private TextBox x3;
        private TextBox z9;
        private TextBox y9;
        private TextBox x9;
        private TextBox z8;
        private TextBox y8;
        private TextBox x8;
        private TextBox z7;
        private TextBox y7;
        private TextBox x7;
        private TextBox precision;
        private Label label5;
        private CheckBox isTextured;
        private TextBox torusSmallR;
        private TextBox torusR;
        private Label label4;
        private Label label6;
        private System.Windows.Forms.ComboBox comboBox1;

        private void InitializeComponent()
        {
            this.comboBox1 = new System.Windows.Forms.ComboBox();
            this.button1 = new System.Windows.Forms.Button();
            this.label1 = new System.Windows.Forms.Label();
            this.radius = new System.Windows.Forms.TextBox();
            this.label2 = new System.Windows.Forms.Label();
            this.height = new System.Windows.Forms.TextBox();
            this.label3 = new System.Windows.Forms.Label();
            this.edge = new System.Windows.Forms.TextBox();
            this.x1 = new System.Windows.Forms.TextBox();
            this.y1 = new System.Windows.Forms.TextBox();
            this.z1 = new System.Windows.Forms.TextBox();
            this.x4 = new System.Windows.Forms.TextBox();
            this.y4 = new System.Windows.Forms.TextBox();
            this.z4 = new System.Windows.Forms.TextBox();
            this.z2 = new System.Windows.Forms.TextBox();
            this.y2 = new System.Windows.Forms.TextBox();
            this.x2 = new System.Windows.Forms.TextBox();
            this.z5 = new System.Windows.Forms.TextBox();
            this.y5 = new System.Windows.Forms.TextBox();
            this.x5 = new System.Windows.Forms.TextBox();
            this.z6 = new System.Windows.Forms.TextBox();
            this.y6 = new System.Windows.Forms.TextBox();
            this.x6 = new System.Windows.Forms.TextBox();
            this.z3 = new System.Windows.Forms.TextBox();
            this.y3 = new System.Windows.Forms.TextBox();
            this.x3 = new System.Windows.Forms.TextBox();
            this.z9 = new System.Windows.Forms.TextBox();
            this.y9 = new System.Windows.Forms.TextBox();
            this.x9 = new System.Windows.Forms.TextBox();
            this.z8 = new System.Windows.Forms.TextBox();
            this.y8 = new System.Windows.Forms.TextBox();
            this.x8 = new System.Windows.Forms.TextBox();
            this.z7 = new System.Windows.Forms.TextBox();
            this.y7 = new System.Windows.Forms.TextBox();
            this.x7 = new System.Windows.Forms.TextBox();
            this.precision = new System.Windows.Forms.TextBox();
            this.label5 = new System.Windows.Forms.Label();
            this.isTextured = new System.Windows.Forms.CheckBox();
            this.torusSmallR = new System.Windows.Forms.TextBox();
            this.torusR = new System.Windows.Forms.TextBox();
            this.label4 = new System.Windows.Forms.Label();
            this.label6 = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // comboBox1
            // 
            this.comboBox1.FormattingEnabled = true;
            this.comboBox1.Items.AddRange(new object[] {
            "Cube",
            "Cone",
            "Cylinder",
            "Bezier",
            "Torus"});
            this.comboBox1.Location = new System.Drawing.Point(12, 12);
            this.comboBox1.Name = "comboBox1";
            this.comboBox1.Size = new System.Drawing.Size(121, 21);
            this.comboBox1.TabIndex = 0;
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(165, 10);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(75, 23);
            this.button1.TabIndex = 1;
            this.button1.Text = "Show";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(13, 105);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(40, 13);
            this.label1.TabIndex = 2;
            this.label1.Text = "Radius";
            // 
            // radius
            // 
            this.radius.Location = new System.Drawing.Point(71, 102);
            this.radius.Name = "radius";
            this.radius.Size = new System.Drawing.Size(50, 20);
            this.radius.TabIndex = 3;
            this.radius.Text = "10";
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(15, 131);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(38, 13);
            this.label2.TabIndex = 4;
            this.label2.Text = "Height";
            // 
            // height
            // 
            this.height.Location = new System.Drawing.Point(71, 128);
            this.height.Name = "height";
            this.height.Size = new System.Drawing.Size(50, 20);
            this.height.TabIndex = 5;
            this.height.Text = "15";
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(7, 157);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(58, 13);
            this.label3.TabIndex = 6;
            this.label3.Text = "Base edge";
            // 
            // edge
            // 
            this.edge.Location = new System.Drawing.Point(71, 154);
            this.edge.Name = "edge";
            this.edge.Size = new System.Drawing.Size(50, 20);
            this.edge.TabIndex = 8;
            this.edge.Text = "20";
            // 
            // x1
            // 
            this.x1.Location = new System.Drawing.Point(165, 102);
            this.x1.Name = "x1";
            this.x1.Size = new System.Drawing.Size(26, 20);
            this.x1.TabIndex = 10;
            this.x1.Text = "1";
            // 
            // y1
            // 
            this.y1.Location = new System.Drawing.Point(197, 102);
            this.y1.Name = "y1";
            this.y1.Size = new System.Drawing.Size(26, 20);
            this.y1.TabIndex = 11;
            this.y1.Text = "1";
            // 
            // z1
            // 
            this.z1.Location = new System.Drawing.Point(229, 102);
            this.z1.Name = "z1";
            this.z1.Size = new System.Drawing.Size(26, 20);
            this.z1.TabIndex = 12;
            this.z1.Text = "1";
            // 
            // x4
            // 
            this.x4.Location = new System.Drawing.Point(165, 131);
            this.x4.Name = "x4";
            this.x4.Size = new System.Drawing.Size(26, 20);
            this.x4.TabIndex = 13;
            this.x4.Text = "1";
            // 
            // y4
            // 
            this.y4.Location = new System.Drawing.Point(197, 131);
            this.y4.Name = "y4";
            this.y4.Size = new System.Drawing.Size(26, 20);
            this.y4.TabIndex = 14;
            this.y4.Text = "1";
            // 
            // z4
            // 
            this.z4.Location = new System.Drawing.Point(229, 131);
            this.z4.Name = "z4";
            this.z4.Size = new System.Drawing.Size(26, 20);
            this.z4.TabIndex = 15;
            this.z4.Text = "1";
            // 
            // z2
            // 
            this.z2.Location = new System.Drawing.Point(335, 102);
            this.z2.Name = "z2";
            this.z2.Size = new System.Drawing.Size(26, 20);
            this.z2.TabIndex = 18;
            this.z2.Text = "1";
            // 
            // y2
            // 
            this.y2.Location = new System.Drawing.Point(303, 102);
            this.y2.Name = "y2";
            this.y2.Size = new System.Drawing.Size(26, 20);
            this.y2.TabIndex = 17;
            this.y2.Text = "1";
            // 
            // x2
            // 
            this.x2.Location = new System.Drawing.Point(271, 102);
            this.x2.Name = "x2";
            this.x2.Size = new System.Drawing.Size(26, 20);
            this.x2.TabIndex = 16;
            this.x2.Text = "1";
            // 
            // z5
            // 
            this.z5.Location = new System.Drawing.Point(335, 131);
            this.z5.Name = "z5";
            this.z5.Size = new System.Drawing.Size(26, 20);
            this.z5.TabIndex = 21;
            this.z5.Text = "-1";
            // 
            // y5
            // 
            this.y5.Location = new System.Drawing.Point(303, 131);
            this.y5.Name = "y5";
            this.y5.Size = new System.Drawing.Size(26, 20);
            this.y5.TabIndex = 20;
            this.y5.Text = "1";
            // 
            // x5
            // 
            this.x5.Location = new System.Drawing.Point(271, 131);
            this.x5.Name = "x5";
            this.x5.Size = new System.Drawing.Size(26, 20);
            this.x5.TabIndex = 19;
            this.x5.Text = "1";
            // 
            // z6
            // 
            this.z6.Location = new System.Drawing.Point(439, 131);
            this.z6.Name = "z6";
            this.z6.Size = new System.Drawing.Size(26, 20);
            this.z6.TabIndex = 27;
            this.z6.Text = "-1,5";
            // 
            // y6
            // 
            this.y6.Location = new System.Drawing.Point(407, 131);
            this.y6.Name = "y6";
            this.y6.Size = new System.Drawing.Size(26, 20);
            this.y6.TabIndex = 26;
            this.y6.Text = "1";
            // 
            // x6
            // 
            this.x6.Location = new System.Drawing.Point(375, 131);
            this.x6.Name = "x6";
            this.x6.Size = new System.Drawing.Size(26, 20);
            this.x6.TabIndex = 25;
            this.x6.Text = "2";
            // 
            // z3
            // 
            this.z3.Location = new System.Drawing.Point(439, 102);
            this.z3.Name = "z3";
            this.z3.Size = new System.Drawing.Size(26, 20);
            this.z3.TabIndex = 24;
            this.z3.Text = "1";
            // 
            // y3
            // 
            this.y3.Location = new System.Drawing.Point(407, 102);
            this.y3.Name = "y3";
            this.y3.Size = new System.Drawing.Size(26, 20);
            this.y3.TabIndex = 23;
            this.y3.Text = "1";
            // 
            // x3
            // 
            this.x3.Location = new System.Drawing.Point(375, 102);
            this.x3.Name = "x3";
            this.x3.Size = new System.Drawing.Size(26, 20);
            this.x3.TabIndex = 22;
            this.x3.Text = "1";
            // 
            // z9
            // 
            this.z9.Location = new System.Drawing.Point(439, 157);
            this.z9.Name = "z9";
            this.z9.Size = new System.Drawing.Size(26, 20);
            this.z9.TabIndex = 36;
            this.z9.Text = "1";
            // 
            // y9
            // 
            this.y9.Location = new System.Drawing.Point(407, 157);
            this.y9.Name = "y9";
            this.y9.Size = new System.Drawing.Size(26, 20);
            this.y9.TabIndex = 35;
            this.y9.Text = "1";
            // 
            // x9
            // 
            this.x9.Location = new System.Drawing.Point(375, 157);
            this.x9.Name = "x9";
            this.x9.Size = new System.Drawing.Size(26, 20);
            this.x9.TabIndex = 34;
            this.x9.Text = "1";
            // 
            // z8
            // 
            this.z8.Location = new System.Drawing.Point(335, 157);
            this.z8.Name = "z8";
            this.z8.Size = new System.Drawing.Size(26, 20);
            this.z8.TabIndex = 33;
            this.z8.Text = "1";
            // 
            // y8
            // 
            this.y8.Location = new System.Drawing.Point(303, 157);
            this.y8.Name = "y8";
            this.y8.Size = new System.Drawing.Size(26, 20);
            this.y8.TabIndex = 32;
            this.y8.Text = "-2";
            // 
            // x8
            // 
            this.x8.Location = new System.Drawing.Point(271, 157);
            this.x8.Name = "x8";
            this.x8.Size = new System.Drawing.Size(26, 20);
            this.x8.TabIndex = 31;
            this.x8.Text = "1";
            // 
            // z7
            // 
            this.z7.Location = new System.Drawing.Point(229, 157);
            this.z7.Name = "z7";
            this.z7.Size = new System.Drawing.Size(26, 20);
            this.z7.TabIndex = 30;
            this.z7.Text = "1";
            // 
            // y7
            // 
            this.y7.Location = new System.Drawing.Point(197, 157);
            this.y7.Name = "y7";
            this.y7.Size = new System.Drawing.Size(26, 20);
            this.y7.TabIndex = 29;
            this.y7.Text = "1";
            // 
            // x7
            // 
            this.x7.Location = new System.Drawing.Point(165, 157);
            this.x7.Name = "x7";
            this.x7.Size = new System.Drawing.Size(26, 20);
            this.x7.TabIndex = 28;
            this.x7.Text = "0,5";
            // 
            // precision
            // 
            this.precision.Location = new System.Drawing.Point(71, 273);
            this.precision.Name = "precision";
            this.precision.Size = new System.Drawing.Size(100, 20);
            this.precision.TabIndex = 37;
            this.precision.Text = "51";
            // 
            // label5
            // 
            this.label5.AutoSize = true;
            this.label5.Location = new System.Drawing.Point(18, 276);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(50, 13);
            this.label5.TabIndex = 38;
            this.label5.Text = "Precision";
            // 
            // isTextured
            // 
            this.isTextured.AutoSize = true;
            this.isTextured.Location = new System.Drawing.Point(21, 51);
            this.isTextured.Name = "isTextured";
            this.isTextured.Size = new System.Drawing.Size(58, 17);
            this.isTextured.TabIndex = 39;
            this.isTextured.Text = "texture";
            this.isTextured.UseVisualStyleBackColor = true;
            // 
            // torusSmallR
            // 
            this.torusSmallR.Location = new System.Drawing.Point(71, 233);
            this.torusSmallR.Name = "torusSmallR";
            this.torusSmallR.Size = new System.Drawing.Size(50, 20);
            this.torusSmallR.TabIndex = 40;
            // 
            // torusR
            // 
            this.torusR.Location = new System.Drawing.Point(71, 199);
            this.torusR.Name = "torusR";
            this.torusR.Size = new System.Drawing.Size(50, 20);
            this.torusR.TabIndex = 41;
            // 
            // label4
            // 
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(15, 202);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(15, 13);
            this.label4.TabIndex = 42;
            this.label4.Text = "R";
            // 
            // label6
            // 
            this.label6.AutoSize = true;
            this.label6.Location = new System.Drawing.Point(18, 236);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(10, 13);
            this.label6.TabIndex = 43;
            this.label6.Text = "r";
            // 
            // MainWindow
            // 
            this.ClientSize = new System.Drawing.Size(525, 305);
            this.Controls.Add(this.label6);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.torusR);
            this.Controls.Add(this.torusSmallR);
            this.Controls.Add(this.isTextured);
            this.Controls.Add(this.label5);
            this.Controls.Add(this.precision);
            this.Controls.Add(this.z9);
            this.Controls.Add(this.y9);
            this.Controls.Add(this.x9);
            this.Controls.Add(this.z8);
            this.Controls.Add(this.y8);
            this.Controls.Add(this.x8);
            this.Controls.Add(this.z7);
            this.Controls.Add(this.y7);
            this.Controls.Add(this.x7);
            this.Controls.Add(this.z6);
            this.Controls.Add(this.y6);
            this.Controls.Add(this.x6);
            this.Controls.Add(this.z3);
            this.Controls.Add(this.y3);
            this.Controls.Add(this.x3);
            this.Controls.Add(this.z5);
            this.Controls.Add(this.y5);
            this.Controls.Add(this.x5);
            this.Controls.Add(this.z2);
            this.Controls.Add(this.y2);
            this.Controls.Add(this.x2);
            this.Controls.Add(this.z4);
            this.Controls.Add(this.y4);
            this.Controls.Add(this.x4);
            this.Controls.Add(this.z1);
            this.Controls.Add(this.y1);
            this.Controls.Add(this.x1);
            this.Controls.Add(this.edge);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.height);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.radius);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.comboBox1);
            this.Name = "MainWindow";
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string whichOne = (string)comboBox1.SelectedItem;
            whichOne = whichOne.ToLower();
            bool putTexture = isTextured.Checked;
            using (XWindow xwin = new XWindow())
            {
                xwin.InitializeDevice();
                if (whichOne.Equals("cube"))
                {
                    xwin.CreateBox(Convert.ToSingle(edge.Text),Convert.ToSingle(edge.Text), Convert.ToSingle(height.Text), putTexture);
                }
                else if (whichOne.Equals("cone"))
                {
                    xwin.CreateCone(Convert.ToInt32(precision.Text), Convert.ToSingle(height.Text), Convert.ToSingle(radius.Text), putTexture);
                }
                else if (whichOne.Equals("cylinder"))
                {
                    xwin.CreateCylinder(Convert.ToInt32(precision.Text), Convert.ToSingle(height.Text), Convert.ToSingle(radius.Text), putTexture);
                }
                else if (whichOne.Equals("bezier"))
                {
                    xwin.CreateBezierSurface(Convert.ToInt32(precision.Text), new Vector3[]{
                        new Vector3(Convert.ToSingle(x1.Text),Convert.ToSingle(y1.Text),Convert.ToSingle(z1.Text)),
                        new Vector3(Convert.ToSingle(x2.Text),Convert.ToSingle(y2.Text),Convert.ToSingle(z2.Text)),
                        new Vector3(Convert.ToSingle(x3.Text),Convert.ToSingle(y3.Text),Convert.ToSingle(z3.Text)),

                        new Vector3(Convert.ToSingle(x4.Text),Convert.ToSingle(y4.Text),Convert.ToSingle(z4.Text)),
                        new Vector3(Convert.ToSingle(x5.Text),Convert.ToSingle(y5.Text),Convert.ToSingle(z5.Text)),
                        new Vector3(Convert.ToSingle(x6.Text),Convert.ToSingle(y6.Text),Convert.ToSingle(z6.Text)),

                        new Vector3(Convert.ToSingle(x7.Text),Convert.ToSingle(y7.Text),Convert.ToSingle(z7.Text)),
                        new Vector3(Convert.ToSingle(x8.Text),Convert.ToSingle(y8.Text),Convert.ToSingle(z8.Text)),
                        new Vector3(Convert.ToSingle(x9.Text),Convert.ToSingle(y9.Text),Convert.ToSingle(z9.Text))

                    }, 3, putTexture);
                }
                else if (whichOne.Equals("torus"))
                {
                    xwin.CreateTorus(Convert.ToInt32(precision.Text), Convert.ToSingle(torusR.Text), Convert.ToSingle(torusSmallR.Text), putTexture);
                }
                //xwin.RenderFigure();
                //xwin.LoadXFile("D:\\x\\cone.x");
                //              xwin.LoadXFile("D:\\SSStudia\\mgr Semestr II\\3d\\x\\vs\\woman.X");
                xwin.ShowDialog(this);
            }
        }

        public static void Main(string[] args)
        {
            MainWindow mw = new MainWindow();
            mw.InitializeComponent();
            System.Windows.Forms.Application.Run(mw);   
        }

    }
}

